
" Start up {{{
" 关闭兼容模式
set nocompatible

" 开启文件类型检查, 加载对应插件，并且载入与该类型对应的缩进规则
filetype plugin indent on

" hide Menu bar and Tool bar
set guioptions-=m
set guioptions-=T

" 打开文件监视
set autoread
" 不生成备份文件
set nobackup
" 不生成临时文件
set noswapfile
" 不生成 undo 文件
set noundofile

" }}}

" Format {{{
" break line encounter a space character
set linebreak

" 按下回车键后，下一行的缩进会自动跟上一行的缩进保持一致
set autoindent
set smartindent
" Insert model 按下 Tab 键时，Vim Insert的空格数
set tabstop=2
set expandtab
" 格式化时缩进尺寸
set shiftwidth=2
" 让 vim 把连续数量的空格视为一个制表符
set softtabstop=2
set foldmethod=indent

" 设置回车换行兼容
set fileformats=unix,dos
" }}}

" Apperance {{{
" Max window
au GUIEnter * simalt ~x

set guifont=Consolas:h16

if has('win32') || has( 'win64' )
  color desert
elseif has('unix')
  color default
endif

" Don't fold content default.
set nofoldenable

" open syntax high light
syntax on

" 光标所在的当前行高亮
set cursorline

" 高亮搜索内容
set hlsearch

" 输入搜索模式时，每输入一个字符，就自动跳到第一个匹配的结果
set incsearch

" 搜索时忽略大小写
set ignorecase

" match hight light
set showmatch

" }}}
" point to my own .vimrc
"source $VIM/user/.vimrc
syntax on

" General {{{
" 显示行号
set number

"显示相对行号
"set relativenumber

set ruler

"让vimrc配置变更立即生效
autocmd BufWritePost $MYVIMRC source $MYVIMRC

" Vim 的默认寄存器和系统剪贴板共享
set clipboard+=unnamed

" 设置 alt 键不映射到菜单栏
set winaltkeys=no

" }}}


" Lang & Encoding {{{
" 设置vim内部编码
set encoding=utf-8
" 设置编辑文件时的编码
set fileencoding=utf-8
" 设置 Vim 能识别的编码
set fileencodings=utf-8,gbk2312,gbk,gb18030,cp936,ucs-bom,cp936,big5,cuc-jp,cuc-kr,latin
" 设置终端模式(非 GUI 模式)下的编码
set termencoding=utf-8
set langmenu=zh_CN.UTF-8
let $LANG = 'en_US.UTF-8'
" 防止特殊符号无法显示
set ambiwidth=double
" 解决 console 输出乱码
language messages zh_CN.UTF-8

" }}}


" Keymap {{{

" 所有模式
" F12 open $MYVIMRC
noremap <F12> :e $MYVIMRC<CR>
noremap <C-s> <Esc>:w!<CR>
noremap <A-Up> <Esc>ddP
noremap <A-Down> <Esc>ddp

" 普通模式
" Y 按照习惯从光标处复制到行尾 
nnoremap Y y$

nnoremap <CR> i<CR><Esc>
nnoremap <C-CR> o<Esc>

nnoremap <S-CR> O<Esc>


" Insert model keymap
" 插入模式
" 移动光标 alt + 方向键
inoremap <A-j> <Down>
inoremap <A-k> <Up>
inoremap <A-h> <Left>
inoremap <A-l> <Right>
inoremap <S-Insert> <C-o>p

inoremap <A-S-[> <Esc>A {

" 回车相关
inoremap <C-CR> <Esc>o
inoremap <S-CR> <Esc>O
inoremap <C-A-CR> <CR><Esc>kA

"Toggle Menu and Toolbar
map <A-F9> :if &guioptions =~# 'T' 
        \set guioptions-=T 
        \set guioptions-=m 
    \else 
        \set guioptions+=T 
        \set guioptions+=m 
    \endif


" Command model keymap
" command line paste
cmap <S-Insert>	<C-R>+

" 打开当前目录 window
map <leader>ex :!start explorer %:p:h<CR>

" }}}

" console {{{
" 命令模式下，底部命令行Tab 键自动补全
set wildmenu
set wildmode=longest:list,full
" }}}
"
"
" plug-vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Specify a directory for plugins

call plug#begin('$HOME/vimfiles/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches junegunn/vim-easy-align
"Plug 'vim-airline/vim-airline'
"Plug 'lilydjwg/colorizer'
Plug 'plasticboy/vim-markdown'
"Plug 'mattn/gist-vim'

" Any valid git URL is allowed
"Plug 'junegunn/vim-github-dashboard'

" Multiple Plug commands can be written in a single line using | separators
"Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
"Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

call plug#end()
